﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NDepot.Manager.Base;
using NDepot.Manager;
using NDepot.Models.UI;
using System.Net.Mime;

namespace NDepot.Controllers
{
    public class InfoController : DepotController
    {
        private IProductManager _ProductManager;
        private IOrderManager _OrderManager;

        public InfoController()
            : this(ProductManager.GetInstance(), OrderManager.GetInstance())
        {
        }

        public InfoController(IProductManager product_r, IOrderManager order_r)
        {
            _ProductManager = product_r;
            _OrderManager = order_r;
        }

        //
        // GET: /Info/

        public ActionResult WhoBought(string id)
        {
            IList<OrderInput> orders = _ProductManager.GetOrdersByProductId(id);

            if (!String.IsNullOrEmpty(Request.AcceptTypes[0]) || Request.AcceptTypes[0] != "application/xml")
                return View(orders);
            else
                return new ContentResult
                {
                    ContentType = "application/xml",
                    Content = Request.AcceptTypes[0],//Helper.GetXMLFromObject(orders),
                    ContentEncoding = System.Text.Encoding.UTF8
                };
        }
    }
}
